
public class Dyck {
	/**
	 * Überprüft, ob das Dyck-Wort korrekt geklammert ist.
	 * @return
	 */
	public static boolean isDyckD2(char[] input)
	{
		ArrayStack stack = new ArrayStack();
		
		for (char c : input) {
			switch (c) {
			case '(': case '[':
				stack.stackPush(c);
				break;
			case ']': 
				if (stack.stackEmpty() || stack.stackPop().toString().toCharArray()[0] != '[')
					return false;
				break;
			case ')':
				if (stack.stackEmpty() || stack.stackPop().toString().toCharArray()[0] != '(')
					return false;
				break;
			default:
				return false;
			}
		}
		return stack.stackEmpty();
	}
}
